package com.example.demo.web;


import com.example.demo.Service.EnployeeService;
import com.example.demo.dao.EmployeeDao;
import javafx.scene.paint.Stop;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.Query;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@SpringBootTest
@RunWith(SpringRunner.class)
public class Employee {
    @Resource
    private EmployeeDao employeeDao;

    @RequestMapping("/ss")
    public List<com.example.demo.entity.Employee> ni(){
        List<com.example.demo.entity.Employee> list = employeeDao.findAllBy();
        return list;
    }


    @RequestMapping("/aa")
    public com.example.demo.entity.Employee ns(){
       com.example.demo.entity.Employee employee = employeeDao.findAllByName("颜亮");
        return employee;
    }
    @RequestMapping("/qu")
    public Page<com.example.demo.entity.Employee> ax(){
        int page=1,size=3;
        Sort sort=Sort.by(Sort.Direction.DESC,"id");
        Pageable pageable = PageRequest.of(page,size,sort);
        Page<com.example.demo.entity.Employee> page1 = employeeDao.employeePage(pageable);
        System.out.println("总条数："+page1.getTotalElements());
        System.out.println("总页数："+page1.getTotalPages());
        System.out.println("当前页数："+page1.getNumber()+1);
        System.out.println("当前页记录条数："+page1.getNumberOfElements());
        return page1;
    }
    @Resource
    private EnployeeService enployeeService;

    @RequestMapping("/qd")
    public Page<com.example.demo.entity.Employee> ax1(){
        int page=1,size=3;
        Sort sort=Sort.by(Sort.Direction.DESC,"id");
        Pageable pageable = PageRequest.of(page,size,sort);

        Map<String,String> map = new HashMap<>();
        map.put("name","张三");
        map.put("id","1");
        Page<com.example.demo.entity.Employee> page1 = enployeeService.findAll(map,pageable);
        System.out.println("总条数："+page1.getTotalElements());
        System.out.println("总页数："+page1.getTotalPages());
        System.out.println("当前页数："+page1.getNumber()+1);
        System.out.println("当前页记录条数："+page1.getNumberOfElements());
        return page1;
    }



}
